package top.infopub.mgr.cap.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import top.infopub.generic.GenericDao;
import top.infopub.generic.GenericServiceImpl;
import top.infopub.mgr.cap.dao.LoanFinDetailDao;
import top.infopub.mgr.cap.domain.LoanFinDetailDomain;
import top.infopub.mgr.cap.service.LoanFinDetailService;
import top.infopub.mgr.sts.domain.QaCapDetailDomain;
import top.infopub.model.cap.LoanFinDetail;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.common.collect.Maps;

@Service
public class LoanFinDetailServiceImpl extends GenericServiceImpl<LoanFinDetail, String> implements
		LoanFinDetailService {

	@Autowired
	private LoanFinDetailDao loanFinDetailDao;
	
	@Override
	public GenericDao<LoanFinDetail, String> getDao() {
		return loanFinDetailDao;
	}

    @Override
    public Page<QaCapDetailDomain> selectQaDataByWhere(Page<QaCapDetailDomain> page, String proCode) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        return (Page<QaCapDetailDomain>)loanFinDetailDao.selectByProCode(proCode);
    }

    @Override
    public BigDecimal selectTotalLoanAmount(String proCode) {
        return loanFinDetailDao.selectTotalLoanAmount(proCode);
    }

    @Override
    public Page<LoanFinDetailDomain> selectDataByWhere(Date dateStart, Date dateEnd, String type,
                                                       String orgId, String orgProName,
                                                       Page<LoanFinDetailDomain> page) {
        PageHelper.startPage(page.getPageNum(), page.getPageSize());
        Map<String, Object> where = Maps.newHashMap();
        where.put("loanDateStart", dateStart);
        where.put("loanDateEnd", dateEnd);
        if(type.equals("2")){//区域公司
            where.put("hrOrgAreaId", orgId);
        }else if(type.equals("3")){//项目公司
            where.put("hrOrgProId", orgId);
        }
        where.put("proName", orgProName);
        return (Page<LoanFinDetailDomain>)loanFinDetailDao.selectDataByWhere(where);
    }

}